<?php

namespace App\Console\Commands;

use App\Model\OrderTable;
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Log;

class CancelOrder extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'cancelOrder';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '取消未匹配成功的订单';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {

//        Log::info($this->description . '——开始执行。。');


//        检查所有-> 匹配中的订单  判断时间   调用退款 操作
        $time = strtotime('1970-01-01 ' . date('H:i:s'));
        $res=OrderTable::ORM()->where('order_type', 1)->where('pay_type', 2)->where('status', 1)->where('start_time', '<=', $time)->where('day_time', '<=', time())->get();

        $i=0;
        foreach ($res as $v){
            OrderTable::orderBack($v->order_id);
            Log::info("取消订单{$v->order_id}");
            $i++;
        }

        if($i){
            Log::info($this->description . '——开始执行。。共取消匹配中'.$i.'个');
        }

    }
}
